{__NOLAYOUT__}
{include file="../application/app/view/header.html" /}
</head>
<body class="container-fluid">
  <div class="col-md-12">
    <div class="alert kesn_prompt"></div>
  </div>
<div >
  <h3 align="center" id="questions_id" data-questions_id="{$questions_id}">{$title}</h3>
  <p>
    <div>ID: <span>{$user_info.user_id}</span> </div>
    <div>姓名：<span>{$user_info.user_name}</span></div>
    {if condition="$ifdone eq 'done'"}<div>分数：<span>{$score}</span></div>{/if}
  </p>
  {if condition="$ifdone eq 'done'"}
  <form role="form">
  <ul id="question_content">
      {volist name="question_list" id="question" key="k"}
      <li class="_item list-group-item" data-type="{$question.type}">
      <p>Q{$question.question_id}:{$question.question}</p>
      {switch name="question.type"}
      {case value="1"}
      {volist name="$question.answers" id="answer" key="i"}
        <div class="row">
          <div class="col-md-6">
            <label class="radio" for="radio{$k}{$i}" {if condition="$question.iftrue neq '1'"} {if condition="$question.user_answer eq $i"} style="color:#E74C3C;"{/if} {/if}>
              <input type="radio"  value="" id="radio{$k}{$i}" data-toggle="radio" class="custom-radio" {if condition="$question.true_answer eq $i"} checked="checked" {/if}><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
            {$answer}
            </label>
          </div>
        </div>
        {/volist}
        {/case}
        {case value="2"}
        {volist name="$question.answers" id="answer" key="i"}
        <div class="row">
          <div class="col-md-6">
            <label class="checkbox col-sm-6" for="checkbox{$k}{$i}" {if condition="$question.iftrue neq '1'"}{in name="i" value="$question.user_answer"} style="color:#E74C3C;" {/in} {/if}>
              <input type="checkbox" value="" id="checkbox{$k}{$i}" data-toggle="checkbox" class="custom-checkbox input-sm" {in name="i" value="$question.true_answer" } checked="checked" {/in} ><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
              {$answer}
              </label>
          </div>
        </div>
        {/volist}
        {/case}
        {case value="3"}
        <div class="row">
          <div class="col-md-6">
              <textarea class="form-control" rows="3" {if condition="$question.iftrue neq '1'"} style="color:#E74C3C;"{/if}>{$question.user_answer}</textarea>
              <textarea class="form-control" rows="3">{$question.true_answer}</textarea>
          </div>
        </div>
        {/case}
        {/switch} 
        </li>
    {/volist}
 </ul>
 {$page}
{/if}
{if condition="$ifdone eq 'never'"}
<ul id="question_content">
   {volist name="question_list" id="question" key="k"}
      <li class="_item list-group-item" data-type="{$question.type}">
      <p>Q <span class="question_id">{$question.question_id}</span>:{$question.question}</p>
      {switch name="question.type"}
      {case value="1"}
      {volist name="$question.answers" id="answer" key="i"}
        <div class="row">
          <div class="col-md-6">
            <label class="radio" for="radio{$k}{$i}" >
              <input type="radio" name="{$k}" value="{$i}" id="radio{$k}{$i}" data-toggle="radio" class="custom-radio"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
            {$answer}
            </label>
          </div>
        </div>
        {/volist}
        {/case}
        {case value="2"}
        {volist name="$question.answers" id="answer" key="i"}
        <div class="row">
          <div class="col-md-6">
            <label class="checkbox col-sm-6" for="checkbox{$k}{$i}">
              <input type="checkbox" name="{$k}" value="{$i}" id="checkbox{$k}{$i}" data-toggle="checkbox" class="custom-checkbox input-sm" ><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
              {$answer}
              </label>
          </div>
        </div>
        {/volist}
        {/case}
        {case value="3"}
        <div class="row">
          <div class="col-md-6">
              <textarea class="form-control" rows="3"></textarea>
          </div>
        </div>
        {/case}
        {/switch} 
        </li>
    {/volist}
</ul>
<div align="right">
  <button type="button" class="btn btn-primary save_answer">提交</button>
  </div>
{$page}
{/if}
</form>

 </div>
{include file="../application/app/view/footer.html" /}
<script type="text/javascript">
  // $('.radio').find('input').radiocheck();
  // $('.checkbox').find('input').radiocheck();
</script>
{if condition="$ifdone eq 'never'"}
<script type="text/javascript">
$('.save_answer').click(function(){
  var questions_id = $('#questions_id').attr('data-questions_id');
  var user_answer = new Array;
  $('#question_content').find('._item').each(function(){
    var _this = $(this);
    var sub_user_answer = {};
    sub_user_answer['question_id'] = _this.find('.question_id').html();
    sub_user_answer['type'] = _this.attr('data-type');
    switch (sub_user_answer['type']){
      case '1':
      var radio = _this.find('input');
      var check_radio = 0;
      for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
          check_radio = i+1;
        }
      }
      sub_user_answer['answer'] = check_radio;
      break;
      case '2':
        var checkbox = _this.find('input');
        var check_checkbox = new Array;
        for (var i = 0; i < checkbox.length; i++) {
          if (checkbox[i].checked) {
            a = i+1;
            check_checkbox.push(a);
          }
        }
        sub_user_answer['answer'] = check_checkbox.join('&');
      break;
      case '3':
      sub_user_answer['answer'] = _this.find('textarea').val();
      break;
    }
    sub_user_answer['iftrue'] = false;
    user_answer.push(sub_user_answer);

 });
  $.ajax({
       url: "save_user_answer",    //请求的url地址
      dataType: "json",   //返回格式为json
      async: true, //请求是否异步，默认为异步，这也是ajax重要特性
      data: {"questions_id":questions_id,"user_answer":user_answer },    //参数值
      type: "POST",   //请求方式
      success: function(data) {
        if (data.err == '0') {
          kesn_prompt('success',data.content);
          $('.save_answer').attr('disabled','disabled');
        }else{
          kesn_prompt('fail',data.content);
        }
      }
  });


});
</script>
{/if}
</footer>
</body>
</html>
